import {
    createRouter,
    createWebHashHistory
} from 'vue-router'
import {
    useAuthStore
} from '@/store/index.ts'
import {
    useRouter
} from 'vue-router'
import loginView from '@/views/login.vue'
import choosemanView from '@/views/chooseman.vue'
import controllerView from '@/views/controller.vue'
import gameAView from '@/views/gameA.vue'
import gameBView from '@/views/gameB.vue'
import game5View from '@/views/game5.vue'
import mineView from '@/views/mine.vue'
import AchievementsView from '@/views/Achievements.vue'
import untilView from '@/views/until.vue'
import endView from '@/views/end.vue'
import finishView from '@/views/finish.vue'
import game5finishView from '@/views/game5finish.vue'
// const Store = useAuthStore();
const router = createRouter({
    history: createWebHashHistory(
        import.meta.env.BASE_URL),
    routes: [{
            path: "/",
            name: 'controller',
            component: controllerView,
        }, {
            path: "/login",
            name: 'login',
            component: loginView,
        }, {
            path: "/chooseman",
            name: 'chooseman',
            component: choosemanView,
        }, {
            path: "/gameA",
            name: 'gameA',
            component: gameAView,
        }, {
            path: "/gameB",
            name: 'gameB',
            component: gameBView,
        },
        {
            path: "/game5",
            name: 'game5',
            component: game5View,
        },
        {
            path: "/mine",
            name: 'mine',
            component: mineView,
        }, {
            path: "/Achievements",
            name: 'Achievements',
            component: AchievementsView,

        }, {
            path: "/until",
            name: 'until',
            component: untilView,

        }, {
            path: "/end",
            name: 'end',
            component: endView,

        }, {
            path: "/finish",
            name: 'finish',
            component: finishView,

        }, {
            path: "/game5finish",
            name: 'game5finish',
            component: game5finishView,

        }
    ]
})


router.beforeEach((to, from, next) => {
    const routerx = useRouter()
    if (to.path != "/login"&&to.path!='/end') {
        useAuthStore().getnowtime();
    }
    console.log(to.path);
    if (to.path != "/gameA" && to.path != "/gameB" && to.path != "/game5") {
        console.log(1);
        sessionStorage.setItem('nowtopic', 0);
    }
    // console.log(store.pagestate)
    // console.log('当前路由器实例:', currentRouter)
    next();
})

export default router